package Leetcode第一期;

import java.util.HashSet;
import java.util.Set;

/**
 * @author : K k
 * @date : 9:28 2020/5/14
 */
public class 只出现一次的数字_136 {
    public int singleNumber1(int[] nums) {
        int temp=0;
        for (int i=0;i<nums.length;i++){
            temp^=nums[i];
        }
        return temp;
    }

    public int singleNumber2(int[] nums) {
        Set set=new HashSet();
        for (int i=0;i<nums.length;i++){
            if (!set.contains(nums[i])){
                set.add(nums[i]);
            }else {
                set.remove(nums[i]);
            }
        }
        return  (int) set.iterator().next();
    }
}
